//
//  ZJImagesScrollView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/28.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJImagesScrollView.h"

@interface ZJImagesScrollView ()
/** scrollView */
@property (nonatomic, strong) UIScrollView *scrollView;
/** 下划线 */
@property (nonatomic, strong) UILabel *underLine;
@end

@implementation ZJImagesScrollView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame title:title];
    if (self) {
        [self addSubview:self.scrollView];
        [self addSubview:self.underLine];
    }
    return self;
}



- (void)updateUI_dataArray:(NSArray *)dataArray{

    CGFloat imageW = 100 * [UIScreen zj_screenWScale];
    CGFloat imageH = self.scrollView.height - 10 * [UIScreen zj_screenHScale];
    CGFloat space = 12 * [UIScreen zj_screenWScale];
    CGFloat maxWidth = 0;
    for (int i = 0; i < dataArray.count; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * (imageW + space), 0, imageW, imageH)];
        [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,[dataArray[i] objectForKey:@"FILE_PATH"]]] placeholderImage:PlaceholderImage];
        imageView.tag = i;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_imageView:)];
        [imageView addGestureRecognizer:tapGester];
        maxWidth = imageView.right;
        [self.scrollView addSubview:imageView];
    }
    self.scrollView.contentSize = CGSizeMake(maxWidth, self.scrollView.height);
}


- (void)action_imageView:(UITapGestureRecognizer *)sender{
    if (self.delegate) {
        [self.delegate ZJImagesScrollViewDelegate_index:sender.view.tag];
    }
}


- (UIScrollView *)scrollView{
    if (_scrollView == nil){
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(self.titleLabel.x, self.titleLabel.bottom, self.width - 2 * self.titleLabel.x, self.height - self.titleLabel.bottom - 1)];
        _scrollView.size = _scrollView.size;
    }
    return _scrollView;
}

- (UILabel *)underLine{
    if (_underLine == nil){
        _underLine = [[UILabel alloc] initWithFrame:CGRectMake(0, self.height - 1, self.width, 1)];
        _underLine.backgroundColor = [UIColor zj_colorWithHexString:@"f2f2f2"];
        
    }
    return _underLine;
}
@end
